﻿using System;
using UnityEngine;
using Yoozoo.Core.Common;
using Yoozoo.Framework.Core;
using Yoozoo.Gameplay.Liberty.AI;
using Yoozoo.Mars.Got;
using System.Collections.Generic;
using com.yoozoo.gta.Art.RpgScene;
using DestroyIt;
namespace Yoozoo.Gameplay.Liberty
{
    public class LibertyManager : MonoBehaviour
    {
        public LibertyNpcManager NpcManager { get; set; }

        public LibertyAIManager AIManager { get; set; }

        public LibertySceneManager SceneManager { get; set; }

        public Transform basisCollider;
        
        public float currentFixedTime = 0.02f;
        
        [SerializeField]
        private float initFixedTime = 0.033f;

        private static LibertyManager instance;
        public static LibertyManager GetInstance(string s)
        {
            return instance;
        }
        
        public void Initialize()
        {
            NpcManager = GetComponentInChildren<LibertyNpcManager>();
            BlueprintUtils.LibertyManager = this;
            LibertyAIUtils.LibertyManager = this;
            // var destroyPool = transform.AddComponent<ObjectPool>();
            // destroyPool.prefabsToPool = new List<PoolEntry>();
            // var destroyManager = transform.AddComponent<DestructionManager>();
            // var particleManager = transform.AddComponent<ParticleManager>();

        }

        private void Awake()
        {
            instance = this;
        }

        private void OnDestroy()
        {
            BlueprintUtils.LibertyManager = null;
            LibertyAIUtils.LibertyManager = null;
            instance = null;
        }

        private void OnEnable()
        {
            SetPhysicStep();
        }

        public void SwitchBasisCollider(bool enable)
        {
            if (basisCollider)
            {
                basisCollider.gameObject.SetActive(enable);
            }
        }

        public void SetPhysicStep()
        {
            float f = initFixedTime;
            if (QualityHelper.QualityMgr && QualityHelper.QualityMgr.CurrentQuality == QualityEnum.Low)
            {
                f = 0.05f;
            }
            
            Time.fixedDeltaTime = f;
            currentFixedTime = Time.fixedDeltaTime;
        }

        private void OnDisable()
        {
            UnSetPhysicStep();
        }

        public void UnSetPhysicStep()
        {
            currentFixedTime = 0.05f;
            Time.fixedDeltaTime = 0.05f;
        }
        

        public void Dispose()
        {
            NpcManager?.Dispose();
            LibertyAnimationClipManager.GetInstance().ClearAll();
        }


    }
}
